#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/1/11 12:08
# @Author : 闫峰
# @File    : execute_strategy.py
import decimal
from decimal import Decimal
import requests
from common.setting import ensure_path_sep
from utils.logging_tool.log_decorator import log_print_decorator_allegro_publish
from utils.mongodb_control.batch_by_mongodb import MongoDBByBatch
from utils.mysqlUtils.db_pool import Database
from utils.mysqlUtils.mongodb_utils import MongoDBLink
from utils.otherutils.batch_processor import BatchProcessor
from utils.redis_control.redis_control import RedisHandler
from testcases.java_Intelligent_publishing.allegro.prod.publish.filter import filter_sku,filter_sku_by_sku_model
switch = True


class ExecuteStrategy:
    strategy_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "HWY-ZH-GZ-RDS-strategy")
    category_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "zhcxkj_center_category_attribute_prod")
    zhcxkj_center_product_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "HWY-ZH-GZ-RDS-Product")
    zhcxkj_center_listing_comprehensive_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"),
                                                      "zhcxkj_center_listing_comprehensive")
    # 定义mongodb

    t_sku_strategy_relation_modb = MongoDBLink(
        uri='mongodb://reader:Vly07YmbY0kLt80Y?@121.37.240.172:8635,121.37.230.118:8635/test?authSource=admin&replicaSet=replica',
        dbname='zhcxkj_center_strategy', coll_name="t_sku_strategy_relation")


    def __init__(self, strategy_id):


        get_t_strategy_allegro = """
             SELECT b.rule_code,
             b.filter_val
     FROM zhcxkj_center_strategy_comprehensive.t_strategy_allegro a
     left join zhcxkj_center_strategy_comprehensive.t_strategy_rule_allegro b on a.id = b.strategy_id
    WHERE a.id = %s
    # and  a.status= 1
        """
        t_strategy_allegro = self.strategy_db.fetch_all_tuple(get_t_strategy_allegro, (strategy_id,))
        self.strategy_id = strategy_id
        self.product_model = None
        self.publish_model = None
        self.listing_model = None
        if not len(t_strategy_allegro):
            raise Exception("策略状态是禁用")
        for i in t_strategy_allegro:
            if i[0] == 'product_model':
                self.product_model = int(i[1])
            elif i[0] == 'publish_model':
                self.publish_model = int(i[1])
            elif i[0] == 'listing_model':
                self.listing_model = int(i[1])
        get_specify_list = f"""
        select import_val from zhcxkj_center_strategy_comprehensive.t_strategy_import_filter_allegro
        where import_id =%s
        """
        self.specify_list = []
        specify_list = self.strategy_db.fetch_all_tuple(get_specify_list, (strategy_id,))
        if len(specify_list):
            self.specify_list = [i[0] for i in specify_list]

        get_source_id_list = f"""
        select source_id 
        from zhcxkj_center_strategy_comprehensive.t_strategy_source_allegro
        where strategy_id =%s
        """
        self.source_id_list = self.strategy_db.fetch_all_tuple(get_source_id_list, (strategy_id,))

    def test_execute_strategy(self):
        t_allegro_listing_template_detail = f"t_allegro_listing_template_detail_{self.listing_model}"
        self.t_allegro_listing_template_detail_modb = MongoDBLink(
            uri='mongodb://reader:Vly07YmbY0kLt80Y?@121.37.240.172:8635,121.37.230.118:8635/test?authSource=admin&replicaSet=replica',
            dbname='zhcxkj_comprehensive_allegro', coll_name=t_allegro_listing_template_detail)

        # MyThreadPool(8).multithreaded(self.execute_strategy_by_source_id, self.source_id_list)
        for source_id in self.source_id_list:
            self.source_id = source_id
            self.execute_strategy_by_source_id(source_id[0])
        # self.execute_strategy_by_source_id(18349)

    def execute_strategy_by_source_id(self, source_id):

        redisExe = RedisHandler("10.158.158.28", 6379, 8, 'Zhcx@2020#redis')
        redis_key = f"allegro_publish_{self.strategy_id}_{source_id}"
        if not redisExe.key_exit(redis_key):
            self.able_category_id_list = self.get_category_id_list(source_id)
            if not redisExe.key_exit(redis_key):
                redisExe.set_string(redis_key,str(self.able_category_id_list))
        if self.specify_list:
            task_list = BatchProcessor.batch_processor(self.specify_list, 1000)
            for task in task_list:
                # 过滤禁售sku
                data_set = self.filter_nosku(data_set=set(task))
                # sku模板过滤
                data_set = self.filter_product_model(data_set=data_set)
                if self.listing_model:
                    # 商品过滤规则过滤
                    data_set = self.filter_listing_model(data_set=data_set)
                # 类目权限过滤
                data_set = self.category_filter(data_set=data_set)
                # 否定规则过滤
                data_set = self.filter_negative(data_set=data_set, source_id=source_id)
                # 刊登执行策略队列过滤
                data_set = self.filter_by_publis_queue(source_id=source_id, data_set=data_set)
                # mysql-listing表过滤
                data_set = self.filter_by_allegro(source_id=source_id, data_set=data_set)
                # ean判重过滤过滤
                # 刊登额度过滤过滤
                db_java_test = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "test_jdw_database")
                if len(data_set):
                    insert_sql = """
                            insert INTO monitor.t_allegro_publish_result
                            (`source_id`,`sku`,`strategy_id`)
                            VALUES (source_id,%s,strategy_id)
                            """
                    rows = db_java_test.execute_many(insert_sql, list(data_set))
                    print(f"插入了{rows} ")

        elif not self.listing_model:
            filters_ObjectId_min = {
                "$and": [
                    {"strategy_relation.strategy_id": self.product_model}
                ]
            }
            projection1 = {"_id": 1, "sku": 1}
            generator = MongoDBByBatch(self.t_sku_strategy_relation_modb).get_data(filters_ObjectId_min, projection1,
                                                                                   500)
            count = 0
            while True:
                try:
                    actual_sku_list = next(generator)
                    data_set = list(map(lambda x: x.get('sku', None), actual_sku_list))
                    count += len(data_set)
                    # 异步分发 提高性能
                    filter_sku.delay(data_set=data_set,source_id=source_id,strategy_id=self.strategy_id)
                    print(f"遍历了{count}")
                except StopIteration:
                    print(f"generator无数据 退出")
                    break
                except Exception as e:
                    print(f"代码报错退出")
                    raise e
        else:
            filters_ObjectId_min = {
                "$and": [
                    {"listingTemplateId": self.listing_model},
                    {"sourceId": source_id}
                ]
            }
            projection1 = {"_id": 1, "sku": 1}
            generator = MongoDBByBatch(self.t_allegro_listing_template_detail_modb).get_data(filters_ObjectId_min,
                                                                                             projection1, 1000)
            while True:
                try:
                    # 从迭代器分批拿出过滤数据，每批次1000
                    actual_sku_list = next(generator)
                    # 过滤掉sku为空的listing数据
                    actual_sku_list = list(filter(lambda x: x.get('sku') != None, actual_sku_list))
                    # map 成集合 元素是 sku
                    data_set = list(map(lambda x: x['sku'], actual_sku_list))
                    filter_sku_by_sku_model.delay(data_set,source_id,self.strategy_id,self.product_model)
                except StopIteration:
                    print(f"generator无数据 退出")
                    break
                except Exception as e:
                    print(f"代码报错退出")
                    raise e

        print(f"strategy_id={self.strategy_id} source_id={source_id}，执行结束")



    @log_print_decorator_allegro_publish(switch=switch, filter_mame="否定策略")
    def filter_negative(self, data_set, source_id):
        res_get_negative_source_sku_list, res_get_negative_plate_id_list, res_get_negative_sku_list = self.get_negative_sku(
            source_id, 6)
        data_set = set(filter(lambda x: x not in res_get_negative_sku_list, data_set))
        return data_set

    @log_print_decorator_allegro_publish(switch=switch, filter_mame="商品过滤规则")
    def filter_listing_model(self, data_set):
        filters_ObjectId_min = {
            "$and": [
                {"sourceId": self.source_id},
                {"sku": {"$in": list(data_set)}}
            ]
        }
        projection1 = {"_id": 1, "sku": 1}
        res_id_index = self.t_allegro_listing_template_detail_modb.select_skip_projection_limit(filters_ObjectId_min,
                                                                                                projection1, "_id",
                                                                                                5000)
        data_set = set(map(lambda x: x['sku'], res_id_index))
        return data_set

    @log_print_decorator_allegro_publish(switch=switch, filter_mame="sku过滤规则")
    def filter_product_model(self, data_set):
        # 指定的sku和产品过滤规则取交集
        filter_sql = {
            "$and": [
                {"sku": {"$in": list(data_set)}},
                {"strategy_relation.strategy_id": self.product_model}
            ]
        }
        projection1 = {"_id": 1, "sku": 1}
        res_id_index = self.t_sku_strategy_relation_modb.select_skip_projection_limit(filter_sql,
                                                                                      projection1, "_id", 1000)
        data_set = set(map(lambda x: x['sku'], res_id_index))
        return data_set

    def handler_sku_set(self, sku_set, source_id, able_category_id_list):
        if not sku_set:
            print(f"strategy_id={self.strategy_id} source_id={source_id}，预期应执行出{len(sku_set)}")
            return
        # 得到一个sku_set  类目权限过滤
        sku_set_filter = self.category_filter(sku_set, able_category_id_list)
        print(f"通过类目权限过滤  剩余 {len(sku_set_filter)} 个")
        # 否定规则
        res_get_negative_source_sku_list, res_get_negative_plate_id_list, res_get_negative_sku_list = self.get_negative_sku(
            source_id, 6)
        sku_set_filter = set(filter(lambda x: x not in res_get_negative_sku_list, sku_set_filter))
        # self.check_sku(self.strategy_id,sku_set_filter)
        if not sku_set_filter:
            print(f"strategy_id={self.strategy_id} source_id={source_id}，预期应执行出{len(sku_set_filter)}")
            return
        sku_set_filter = self.filter_by_publis_queue(source_id, sku_set_filter)
        print(f"通过刊登执行策略队列过滤  剩余 {len(sku_set_filter)} 个")
        if not sku_set_filter:
            print(f"strategy_id={self.strategy_id} source_id={source_id}，预期应执行出{len(sku_set_filter)}")
            return
        sku_set_filter = self.filter_by_allegro(source_id, sku_set_filter)
        print(f"通过mysql-listing表过滤  剩余 {len(sku_set_filter)} 个")
        return sku_set_filter
        # self.check_prod_sku(self.strategy_id,sku_set_filter)

    def check_sku(self, strategy_id, sku_set):
        check_sql = f"""
        SELECT b.sku 
        FROM zhcxkj_center_strategy_comprehensive.t_strategy_queue_allegro a
        LEFT JOIN zhcxkj_center_strategy_comprehensive.t_publish_detail_allegro b on a.id=b.queue_id
        WHERE a.strategy_id= %s
        """
        actual_sku_list = self.strategy_db.fetch_all_tuple(check_sql, (strategy_id,))
        if not len(actual_sku_list):
            actual_sku_set = set()
        actual_sku_set = set(map(lambda x: x[0], actual_sku_list))
        if sku_set != actual_sku_set:
            lack = sku_set - actual_sku_set
            more = actual_sku_set - sku_set
            print()

    def check_prod_sku(self, strategy_id, sku_set):
        check_sql = f"""
        SELECT a.sku 
        FROM zhcxkj_center_strategy_comprehensive.t_publish_detail_allegro a
        WHERE a.sku in %s
        and status in (0,1,2,4,5,7)
        """
        actual_sku_list = self.strategy_db.fetch_all_tuple(check_sql, (sku_set,))
        if not len(actual_sku_list):
            actual_sku_set = set()
        actual_sku_set = set(map(lambda x: x[0], actual_sku_list))
        if sku_set != actual_sku_set:
            lack = sku_set - actual_sku_set
            more = actual_sku_set - sku_set
            print()

    @log_print_decorator_allegro_publish(switch=switch, filter_mame="刊登类目")
    def category_filter(self, data_set):

        get_sku_category = f"""
        SELECT sku,other_node_id 
        FROM zhcxkj_center_category.t_sku_category WHERE platform_type=67 and 	sku in %s
        """
        sku_category = self.category_db.fetch_all_tuple(get_sku_category, (data_set,))
        sku_category = tuple(map(lambda x: (x[0], int(x[1])), sku_category))
        filter_sku_set = set(filter(lambda x: x[1] in self.able_category_id_list, sku_category))
        filter_sku_set = set(map(lambda x: x[0], filter_sku_set))
        return filter_sku_set

    def get_category_id_list(self, source_id):
        get_category_id_list = f"""
        select t.category_id 
        from zhcxkj_center_strategy_comprehensive.t_allegro_publish_source_category t 
        where t.source_id = %s
        """
        category_id_list = self.strategy_db.fetch_all_tuple(get_category_id_list, (source_id,))
        if not len(category_id_list):
            return []
        return list(map(lambda x: x[0], category_id_list))

    def init_strategy(self, strategy_id, source_id):
        get_t_allegro_marketing_strategy = """
         SELECT status,sku_template_id,listing_template_id,strategy_type
         FROM test_zhcxkj_center_strategy_comprehensive.t_allegro_marketing_strategy a
        WHERE a.id = %s
                """
        t_allegro_marketing_strategy = self.db.fetch_all_tuple(get_t_allegro_marketing_strategy, (strategy_id,))
        status = t_allegro_marketing_strategy[0][0]
        if status == 0:
            raise Exception("策略状态是禁用")
        strategy_id = strategy_id
        source_id = source_id
        sku_template_id = t_allegro_marketing_strategy[0][1]
        listing_template_id = t_allegro_marketing_strategy[0][2]
        strategy_type = t_allegro_marketing_strategy[0][3]
        return source_id, sku_template_id, listing_template_id, strategy_type

    def check_actual_offer_id_set(self, expect_offer_id_set):
        t_allegro_listing_template_detail = MongoDBLink(
            uri='mongodb://admin:Zhcx?2021@10.158.158.29:27017/?authSource=admin',
            dbname='test_zhcxkj_java_center', coll_name="t_allegro_strategy_adjust_price_detail")
        filter_sql = {"sourceId": self.source_id, "strategyId": self.strategy_id}
        field_ = {"offerId": 1}
        res = t_allegro_listing_template_detail.select(filter_sql, field_)
        actual_offer_id_set = set(map(lambda x: x['offerId'], res))
        if expect_offer_id_set != actual_offer_id_set:
            print()

    def getCalculationGrossProfitMarginViewModelList(self, calculationFormulaId, orderSourceId, listing_id_list):
        request_json = {
            "input": [

            ]
        }
        for lising in listing_id_list:
            sku_model = {
                "businessTypeCode": "AllegroLocalWarehouse",
                "calculationFormulaId": calculationFormulaId,
                "country": "PL",
                "customerId": 1,
                "orderSourceId": orderSourceId,
                "platformId": 67,
                "price": str(lising[2]),
                "sku": lising[3],
                "warehouseId": 5312,
                "warehouseTypeId": 1
            }
            request_json['input'].append(sku_model)
        request_headers = {
            "Authorization": "Basic aXJvYm90Ym94OmkxcjVvOEJvdGJveA=="
        }
        res = requests.post(
            url="http://priceapi.zhcxkj.com/api/calculationFormula/calculationPrice/getCalculationGrossProfitMarginViewModelList",
            headers=request_headers,
            json=request_json)
        sku_GrossProfitMargin_map = {}
        for data in res.json()['data']:
            sku_GrossProfitMargin_map[data["Sku"] + "@" + '{:.2f}'.format(data["Price"])] = str(
                data['GrossProfitMargin'])
        return sku_GrossProfitMargin_map

    def get_price(self, calculationFormulaId, orderSourceId, sku):
        request_json = {
            "input": {
                "businessTypeCode": "AllegroLocalWarehouse",
                "country": "PL",
                "PlatformId": 67,
                "customerId": 1,
                "orderSourceId": orderSourceId,
                "platformId": 1,
                "skuList": [
                    sku
                ],
                "warehouseId": 5312,
                "warehouseTypeId": 1,
                "CalculationFormulaId": calculationFormulaId
            }
        }
        request_headers = {
            "Authorization": "Basic aXJvYm90Ym94OmkxcjVvOEJvdGJveA=="
        }
        res = requests.post(
            url="http://priceapi.zhcxkj.com/api/CalculationFormula/CalculationPrice/GetCalculatorPriceViewModelList",
            headers=request_headers,
            json=request_json)
        if res.status_code == 200:
            return Decimal(str(res.json()['data'][0]['Price']))

    def filter_adjust_model(self, current_offer_id_set):
        # 还原

        get_data_set = f"""
                SELECT offer_id,price,sku
        FROM `test_zhcxkj_center_listing_comprehensive`.`t_allegro_listing_{self.num}` 
        WHERE offer_id in %s
        """
        listing_id_list = self.db.fetch_all_tuple(get_data_set, (current_offer_id_set,))
        filter_listing_id_list = None
        # 最终售价
        if self.price_adjust_plan == 1:
            filter_listing_id_list = self.handlerFinalsellingprice(listing_id_list)
        # 计算器公式
        elif self.price_adjust_plan == 2:
            filter_listing_id_list = self.handlerCalculatorFormulas(listing_id_list)

        return set(map(lambda x: x[0], filter_listing_id_list))

    def handlerFinalsellingprice(self, listing_id_list):
        """
        调价方案： 最终售价
        根据最终售价算法，得到调整后的价格
        1 如果类型是价格区间
            验证 调整后的价格 在  原始价格*self.min_price ——  原始价格*self.max_price之间
        2 如果是利润区间
            调研计算器得到每一条数据的利润率  验证利润率 是否在 self.min_profit—— self.max_profit 之间
        :param listing_id_list:
        :return:
        """
        filter_listing_id_list = None
        listing_id_list_map = None
        # 将 listing_id_list -> offer_id,price,adjust_price,sku
        if self.sell_price_type == 1:
            listing_id_list_map = list(
                map(lambda x: (x[0], x[1], x[1] * (100 - self.price_percentage) / 100, x[2]),
                    listing_id_list))
        elif self.sell_price_type == 2:
            listing_id_list_map = list(
                map(lambda x: (x[0], x[1], x[1] * (100 + self.price_percentage) / 100, x[2]),
                    listing_id_list))
        elif self.sell_price_type == 3:
            listing_id_list_map = list(
                map(lambda x: (x[0], x[1], x[1] - self.price_percentage, x[2]), listing_id_list))
        elif self.sell_price_type == 4:
            listing_id_list_map = list(
                map(lambda x: (x[0], x[1], x[1] + self.price_percentage, x[2]), listing_id_list))
        # offer_id,price,adjust_price,sku  ->  adjust_price 变成2位小数
        listing_id_list_map = list(
            map(lambda x: (x[0], x[1], x[2].quantize(decimal.Decimal('0.01')), x[3]), listing_id_list_map))
        # 价格区间
        if self.price_adjust_type == 1:
            # 过滤数据
            filter_listing_id_list = list(
                filter(lambda x: (x[1] * self.min_price / 100) <= x[2] <= (x[1] * self.max_price / 100),
                       listing_id_list_map))
        # 利润区间
        elif self.price_adjust_type == 2:
            sku_GrossProfitMargin_map = self.getCalculationGrossProfitMarginViewModelList(
                self.calculator_formula_id, self.source_id, listing_id_list_map)
            listing_id_list_map = list(
                map(lambda x: (
                    x[0], x[1], x[2], sku_GrossProfitMargin_map.get(x[3] + "@" + '{:.2f}'.format(x[2])), x[3]),
                    listing_id_list_map))

            # 过滤掉利润率负数
            def negative(listing_id_list_map):
                a = listing_id_list_map[3]
                return not float(a) < 0.00

            filter_listing_id_list = list(filter(negative, listing_id_list_map))
            filter_listing_id_list = list(
                filter(lambda x: self.min_profit <= Decimal(x[3]) <= self.max_profit,
                       filter_listing_id_list))
        return filter_listing_id_list

    def handlerCalculatorFormulas(self, listing_id_list):
        """
        调价方案： 计算器公式
        根据计算器公式，得到调整后的价格  验证是否在  原始价格*self.min_price ——  原始价格*self.max_price之间
        :param listing_id_list:
        :return:
        """
        # map数据
        listing_id_list_map = list(
            map(lambda x: (x[0], x[1], self.get_price(self.calculator_formula_id, self.source_id, x[2]), x[2]),
                listing_id_list))
        # 过滤数据
        filter_listing_id_list = list(
            filter(lambda x: (x[1] * self.min_price / 100) <= x[2] <= (x[1] * self.max_price / 100),
                   listing_id_list_map))
        return filter_listing_id_list

    @log_print_decorator_allegro_publish(switch=switch, filter_mame="禁售sku")
    def filter_nosku(self, data_set):
        get_category_id_list = f"""
        select t.sku  
        from `zhcxkj-center-product`.rb_product_no_sale  t 
        where t.sku in %s
        and t.platform_type = 67
        """
        nosku_list = self.zhcxkj_center_product_db.fetch_all_tuple(get_category_id_list, (data_set,))
        if not len(nosku_list):
            return data_set
        nosku_list = list(map(lambda x: x[0], nosku_list))
        sku_set = set(filter(lambda x: x not in nosku_list, data_set))
        return sku_set

    @log_print_decorator_allegro_publish(switch=switch, filter_mame="执行队列")
    def filter_by_publis_queue(self, source_id, data_set):
        get_data = f"""
        select sku
        from zhcxkj_center_strategy_comprehensive.t_publish_detail_allegro 
        where sku in %s
        and source_id = %s
        and status in (0,1,2,6)
        """
        exist_data = self.strategy_db.fetch_all_tuple(get_data, (data_set, source_id))
        exist_sku = []
        if len(exist_data):
            exist_sku = list(map(lambda x: x[0], exist_data))

        return set(filter(lambda x: x not in exist_sku, data_set))

    @log_print_decorator_allegro_publish(switch=switch, filter_mame="mysql-listing表")
    def filter_by_allegro(self, source_id, data_set):
        get_data = f"""
        select sku
        from zhcxkj_center_listing_comprehensive.t_allegro_listing_{source_id % 8 + 1} 
        where sku in %s
        and source_id = %s
        and status =3
        """
        exist_data = self.zhcxkj_center_listing_comprehensive_db.fetch_all_tuple(get_data, (data_set, source_id))
        exist_sku = []
        if len(exist_data):
            exist_sku = list(map(lambda x: x[0], exist_data))
        return set(filter(lambda x: x not in exist_sku, data_set))

    def get_negative_sku(self, source_id, strategy_type):
        get_negative_strategy = f"""
            SELECT
                a.id
            FROM
                zhcxkj_center_strategy_comprehensive.t_strategy_allegro a
                LEFT JOIN zhcxkj_center_strategy_comprehensive.t_strategy_rule_allegro b ON a.id = b.strategy_id 
            WHERE
                b.rule_code = 'negation_scope'
                AND b.filter_val =%s
                AND a.STATUS = 1
                    """
        # 查询该策略类型下的所有否定策略id
        res_negative_strategy_id_tuple = self.strategy_db.fetch_all_tuple(get_negative_strategy, (strategy_type,))

        get_negative_strategy_sku = f"""
            SELECT
            -- 	a.import_id,
            -- 	b.strategy_id,
                b.source_id,
                a.rule_code,
                a.import_val 
            FROM
                `zhcxkj_center_strategy_comprehensive`.`t_strategy_import_filter_allegro` a
                LEFT JOIN `zhcxkj_center_strategy_comprehensive`.`t_strategy_source_allegro` b ON a.import_id = b.strategy_id 
            WHERE
                a.import_id in %s
                    """
        # filter_val '策略 1创建促销 2修改促销 3删除促销 4下架 5调价 6刊登 7否定 8发货天数',
        # import_id 策略ID
        # rule_code  # '数据对象 1:渠道sku 2:平台id 3:系统sku',
        res_get_negative_strategy_sku = self.strategy_db.fetch_all_tuple(get_negative_strategy_sku, (
            set(map(lambda x: x[0], res_negative_strategy_id_tuple)),))

        res_get_negative_source_sku = set(
            filter(lambda x: x[1] == '1' and (x[0] == source_id or x[0] == None), res_get_negative_strategy_sku))
        res_get_negative_plate_id = set(
            filter(lambda x: x[1] == '2' and (x[0] == source_id or x[0] == None), res_get_negative_strategy_sku))
        res_get_negative_sku = set(
            filter(lambda x: x[1] == '3' and (x[0] == source_id or x[0] == None), res_get_negative_strategy_sku))
        res_get_negative_source_sku_list = list(map(lambda x: x[2], res_get_negative_source_sku))
        res_get_negative_plate_id_list = list(map(lambda x: x[2], res_get_negative_plate_id))
        res_get_negative_sku_list = list(map(lambda x: x[2], res_get_negative_sku))
        return res_get_negative_source_sku_list, res_get_negative_plate_id_list, res_get_negative_sku_list


if __name__ == '__main__':
    # 9046
    # 9058
    # 9059
    # 9062
    ExecuteStrategyExe = ExecuteStrategy(805)
    ExecuteStrategyExe.test_execute_strategy()
    # ExecuteStrategy(1,9058).check_actual_offer_id_set()
